package tcnplanner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

public class RoomService {

    private HashMap<Integer, Testroom> rooms;

    public RoomService() {
        rooms = new HashMap<Integer, Testroom>();
    }

    public int count() {
        return rooms.size();
    }

    public void create(Testroom r) {
        if (this.findById(r.getRoomNr()) != null) {
            rooms.put(r.getRoomNr(), r);
        }
    }

    public void edit(Testroom r) {
        if (this.findById(r.getRoomNr()) != null) {
            rooms.put(r.getRoomNr(), r);
        }
    }

    public Testroom find(int roomNumber) {
        return this.findById(roomNumber);
    }

    public ArrayList<Testroom> findAll() {
        Iterator roms = rooms.values().iterator();
        ArrayList<Testroom> listrooms = new ArrayList<Testroom>();
        while(roms.hasNext()){
            listrooms.add((Testroom)roms.next());
        }
        return listrooms;
    }

    public Testroom findById(int id) {
        return rooms.get(id);
    }

    public void remove(Testroom room) {
        rooms.remove(room.getRoomNr());
    }

    public void removeAll() {
        rooms.clear();
    }
}
